import { quality, EffectClassType, SkillType, TargetType, LogType, effectKey, Attribute_base } from "../../../shared/face/enums";
import { _Skill, BuffConfig } from "../types";

/**
 * 技能配置生成器 - 简化技能创建过程
 */
export class SkillGenerator {
    
    /**
     * 创建伤害技能
     */
    static createDamageSkill(config: {
        id: string;
        name: string;
        desc: string;
        damageType: '物理攻击' | '魔法攻击' | '真实攻击';
        damageMultiplier: number;
        cooldown?: number;
        quality?: quality;
        buffs?: BuffConfig[];
    }): _Skill {
        return {
            id: config.id,
            quality: config.quality || quality.F,
            classType: EffectClassType.攻击型,
            name: config.name,
            desc: config.desc,
            data: [{
                attKey: config.damageType,
                attRange: config.damageMultiplier
            }],
            effect: [this.getDamageEffectKey(config.damageType)],
            buffs: config.buffs || [],
            cooldown: config.cooldown || 0,
            type: SkillType.主动技能,
            targetType: [TargetType.敌方]
        };
    }
    
    /**
     * 创建治疗技能
     */
    static createHealSkill(config: {
        id: string;
        name: string;
        desc: string;
        healMultiplier: number;
        cooldown?: number;
        quality?: quality;
        buffs?: BuffConfig[];
    }): _Skill {
        return {
            id: config.id,
            quality: config.quality || quality.F,
            classType: EffectClassType.辅助型,
            name: config.name,
            desc: config.desc,
            data: [{
                attKey: '魔法攻击',
                attRange: config.healMultiplier
            }],
            effect: [effectKey.辅助类_生命回复],
            buffs: config.buffs || [],
            cooldown: config.cooldown || 0,
            type: SkillType.主动技能,
            targetType: [TargetType.我方不含自己]
        };
    }
    
    /**
     * 创建属性提升技能
     */
    static createAttributeBoostSkill(config: {
        id: string;
        name: string;
        desc: string;
        attribute: Attribute_base;
        boostMultiplier: number;
        duration?: number;
        cooldown?: number;
        quality?: quality;
    }): _Skill {
        return {
            id: config.id,
            quality: config.quality || quality.F,
            classType: EffectClassType.辅助型,
            name: config.name,
            desc: config.desc,
            data: [{
                attKey: '魔法攻击',
                attRange: config.boostMultiplier,
                attributeName: config.attribute
            }],
            effect: [effectKey.辅助类_属性提升],
            buffs: [{
                id: `${config.attribute}加成`,
                name: `${config.attribute}加成`,
                logType: LogType.治疗,
                duration: config.duration || NaN,
                effectType: '属性',
                attributeModifiers: {
                    [config.attribute]: 10
                }
            }],
            cooldown: config.cooldown || 0,
            type: SkillType.光环技能,
            targetType: [TargetType.我方]
        };
    }
    
    /**
     * 创建护盾技能
     */
    static createShieldSkill(config: {
        id: string;
        name: string;
        desc: string;
        shieldMultiplier: number;
        duration?: number;
        cooldown?: number;
        quality?: quality;
    }): _Skill {
        return {
            id: config.id,
            quality: config.quality || quality.F,
            classType: EffectClassType.辅助型,
            name: config.name,
            desc: config.desc,
            data: [{
                attKey: '魔法攻击',
                attRange: config.shieldMultiplier
            }],
            effect: [effectKey.辅助类_护盾],
            buffs: [{
                id: '护盾',
                name: '护盾',
                logType: LogType.护盾,
                duration: config.duration || NaN,
                effectType: '护盾',
                shieldValue: 100
            }],
            cooldown: config.cooldown || 0,
            type: SkillType.主动技能,
            targetType: [TargetType.我方]
        };
    }
    
    /**
     * 创建复合技能
     */
    static createCompositeSkill(config: {
        id: string;
        name: string;
        desc: string;
        effects: Array<{
            type: 'damage' | 'heal' | 'shield' | 'attribute';
            damageType?: '物理攻击' | '魔法攻击' | '真实攻击';
            attribute?: Attribute_base;
            multiplier: number;
        }>;
        buffs?: BuffConfig[];
        cooldown?: number;
        quality?: quality;
        targetTypes?: TargetType[];
    }): _Skill {
        const data: any[] = [];
        const effects: string[] = [];
        const targetTypes: TargetType[] = config.targetTypes || [];
        
        config.effects.forEach(effect => {
            data.push({
                attKey: effect.damageType || '魔法攻击',
                attRange: effect.multiplier,
                attributeName: effect.attribute
            });
            
            switch (effect.type) {
                case 'damage':
                    effects.push(this.getDamageEffectKey(effect.damageType || '魔法攻击'));
                    if (!targetTypes.includes(TargetType.敌方)) targetTypes.push(TargetType.敌方);
                    break;
                case 'heal':
                    effects.push(effectKey.辅助类_生命回复);
                    if (!targetTypes.includes(TargetType.我方不含自己)) targetTypes.push(TargetType.我方不含自己);
                    break;
                case 'shield':
                    effects.push(effectKey.辅助类_护盾);
                    if (!targetTypes.includes(TargetType.我方)) targetTypes.push(TargetType.我方);
                    break;
                case 'attribute':
                    effects.push(effectKey.辅助类_属性提升);
                    if (!targetTypes.includes(TargetType.我方)) targetTypes.push(TargetType.我方);
                    break;
            }
        });
        
        return {
            id: config.id,
            quality: config.quality || quality.F,
            classType: EffectClassType.全能型,
            name: config.name,
            desc: config.desc,
            data,
            effect: effects,
            buffs: config.buffs || [],
            cooldown: config.cooldown || 0,
            type: SkillType.主动技能,
            targetType: targetTypes
        };
    }
    
    private static getDamageEffectKey(damageType: string): string {
        switch (damageType) {
            case '物理攻击':
                return effectKey.伤害类_物理伤害;
            case '魔法攻击':
                return effectKey.伤害类_魔法伤害;
            case '真实攻击':
                return effectKey.伤害类_真实伤害;
            default:
                return effectKey.伤害类_普通攻击;
        }
    }
}

// 使用示例：
export const exampleSkills = [
    // 简单伤害技能
    SkillGenerator.createDamageSkill({
        id: 'FIREBALL',
        name: '火球术',
        desc: '发射一个火球对敌人造成魔法伤害',
        damageType: '魔法攻击',
        damageMultiplier: 1.5,
        cooldown: 2
    }),
    
    // 治疗技能
    SkillGenerator.createHealSkill({
        id: 'HEAL',
        name: '治疗术',
        desc: '治疗友军',
        healMultiplier: 2.0,
        cooldown: 3
    }),
    
    // 属性提升技能
    SkillGenerator.createAttributeBoostSkill({
        id: 'POWER_AURA',
        name: '力量光环',
        desc: '提升友军物理攻击力',
        attribute: Attribute_base.物理攻击,
        boostMultiplier: 0.5,
        duration: NaN // 永久
    }),
    
    // 复合技能
    SkillGenerator.createCompositeSkill({
        id: 'BATTLE_CRY',
        name: '战斗怒吼',
        desc: '对敌人造成伤害并提升自身攻击力',
        effects: [
            { type: 'damage', damageType: '物理攻击', multiplier: 1.2 },
            { type: 'attribute', attribute: Attribute_base.物理攻击, multiplier: 0.3 }
        ],
        buffs: [{
            id: '攻击力加成',
            name: '攻击力加成',
            logType: LogType.治疗,
            duration: 3,
            effectType: '属性',
            attributeModifiers: {
                '物理攻击': 15
            }
        }],
        cooldown: 4,
        targetTypes: [TargetType.敌方, TargetType.自己]
    })
]; 